namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Web.Mvc;
    using SimpleWebServices;
    using SimpleWebServices.Web.Routing;
    using Xunit;

    public sealed class UriConverterFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<UriConverter>()
                .DerivesFrom<object>()
                .IsAbstractBaseClass()
                .Result);
        }

        [Fact]
        public void ctor_Type()
        {
            Assert.NotNull(new UriConverterDerived(typeof(Controller)));
        }

        [Fact]
        public void ctor_TypeInvalid()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new UriConverterDerived(typeof(string)));
        }

        [Fact]
        public void ctor_TypeNull()
        {
            Assert.Throws<ArgumentNullException>(() => new UriConverterDerived(null as Type));
        }

        [Fact]
        public void op_ToResourcePath_string()
        {
            ResourcePath expected = "/test.en";
            ResourcePath actual = new UriConverterDerived(typeof(ResourceControllerOfIResourceDummy)).ToResourcePath("/test.en.html");

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToResourcePath_stringRoot()
        {
            ResourcePath expected = "/";
            ResourcePath actual = new UriConverterDerived(typeof(ResourceControllerOfIResourceDummy)).ToResourcePath("/");

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToResourcePath_stringDirectory()
        {
            ResourcePath expected = "test/";
            ResourcePath actual = new UriConverterDerived(typeof(ResourceControllerOfIResourceDummy)).ToResourcePath("test/");

            Assert.Equal<string>(expected, actual);
        }

        [Fact]
        public void op_ToResourcePath_stringEmpty()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => new UriConverterDerived(typeof(ResourceControllerOfIResourceDummy)).ToResourcePath(string.Empty));
        }

        [Fact]
        public void op_ToResourcePath_stringNull()
        {
            Assert.Throws<ArgumentNullException>(() => new UriConverterDerived(typeof(ResourceControllerOfIResourceDummy)).ToResourcePath(null as string));
        }
    }
}